<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('代付订单列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 80px">通道：</label>
                            <select name="channelOutId">
                                <option selected=""></option>
                                <option th:each="sysChannel : ${sysChannelOuts}" th:text="${sysChannel.channelOutName}" th:value="${sysChannel.channelOutId}"></option>
                            </select>
                        </li>
                        <li th:if="${user.userType!=1}">
                            <label style="width: 80px">商户号：</label>
                            <input type="text" name="userCode"/>
                        </li>
                        <li>
                            <label style="width: 80px">状态：</label>
                            <select name="status" th:with="type=${@dict.getType('sys_withdraw_status')}">
                                <option selected=""></option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 80px">平台订单号：</label>
                            <input type="text" name="withdrawCode"/>
                        </li>
                        <li>
                            <label style="width: 80px">下游订单号：</label>
                            <input type="text" name="withdrawChildCode"/>
                        </li>
                        <li>
                            <label style="width: 80px">渠道流水号：</label>
                            <input type="text" name="withdrawChannelCode"/>
                        </li>
                        <li>
                            <label style="width: 80px">收款人ifsc：</label>
                            <input type="text" name="receiveIfsc"/>
                        </li>
                        <li class="select-time">
                            <label style="width: 80px">创建时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endTime]"/>
                        </li>
<!--                        <li>-->
<!--                            <label style="width: 80px">代付方式：</label>-->
<!--                            <select name="withdrawRuleType" th:with="type=${@dict.getType('sys_withdraw_rule_type')}">-->
<!--                                <option selected=""></option>-->
<!--                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                            </select>-->
<!--                        </li>-->
<!--                        <li>-->
<!--                            <label style="width: 80px">手续费扣除方式：</label>-->
<!--                            <select name="deductType" th:with="type=${@dict.getType('sys_deduct_type')}">-->
<!--                                <option selected=""></option>-->
<!--                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                            </select>-->
<!--                        </li>-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search();showStatistics()"><i class="fa fa-search"></i> 搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i> 重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 search-collapse">
            <div style="margin-top: 10px">
                <span id="todayWithdrawAmount" type="text" class="btn btn-outline btn-info">今日代付金额</span>
                <span id="todayWithdrawCharge" type="text" class="btn btn-outline btn-info">今日代付手续费</span>
                <span id="todayWithdrawSize" type="text" class="btn btn-outline btn-info">今日成功笔数</span>
            </div>
            <br>
            <div style="margin-top: 3px">
                <span id="allWithdrawAmount" type="text" class="btn btn-outline btn-warning">总代付金额</span>
                <span id="allWithdrawCharge" type="text" class="btn btn-outline btn-warning">总代付手续费</span>
                <span id="allWithdrawSize" type="text" class="btn btn-outline btn-warning">总成功笔数</span>
            </div>
<!--            <br>-->
<!--            <div style="margin-top: 3px">-->
<!--                <button type="text" class="btn btn-outline btn-danger">成功交易总额</button>-->
<!--                <button type="text" class="btn btn-outline btn-danger">成功过订单数</button>-->
<!--                <button type="text" class="btn btn-outline btn-danger">商户收入总金额</button>-->
<!--            </div>-->
        </div>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:withdraw:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:withdraw:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:withdraw:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:withdraw:remove')}]];
    var prefix = ctx + "system/withdraw";

    $(function() {
        showStatistics();
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            exportUrl: prefix + "/export",
            modalName: "代付订单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'withdrawId',
                    title: '商户代付订单id',
                    visible: false,
                    formatter: function(value, row, index) {
                        return '<input name="withdrawId" value='+value+' hidden="hidden">';
                    }
                },
                {
                    field: 'channelOutName',
                    title: '通道名称'
                },
                {
                    field: 'ip',
                    title: '访问ip'
                },
                {
                    field: 'withdrawCode',
                    title: '平台相关订单号'
                },
                {
                    field: 'withdrawChildCode',
                    title: '下游订单号'
                },
                {
                    field: 'withdrawChannelCode',
                    title: '渠道流水号'
                },
                {
                    field: 'userCode',
                    title: '商户编号'
                },
                {
                    field: 'withdrawAmount',
                    title: '代付易金额'
                },
                {
                    field: 'withdrawCharge',
                    title: '手续费'
                },
                {
                    field: 'withdrawLastAmount',
                    title: '实际金额'
                },
                {
                    field: 'receiveIfsc',
                    title: '收款人ifsc'
                },
                {
                    field: 'receiveBankname',
                    title: '收款人银行名字'
                },
                {
                    field: 'receiveBankaccount',
                    title: '收款人银行账号'
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        if (value==0){
                            return "处理中";
                        }else if(value==1){
                            return '<a style="color: green">成功</a>';
                        }else {
                            return '<a style="color: red">失败</a>';
                        }
                    }
                },
                {
                    field: 'createTime',
                    title: '提交时间'
                },
                {
                    field: 'orderRemark',
                    title: '备注'
                },
                {
                    field: 'receiveMobile',
                    title: '收款人手机号'
                },
                {
                    field: 'receiveName',
                    title: '收款人名称'
                },
                {
                    field: 'receiveEmail',
                    title: '收款人邮箱'
                },
                {
                    field: 'withdrawRuleType',
                    title: '代付方式',
                    formatter: function(value, row, index) {
                        if (value==0){
                            return "自动";
                        }else {
                            return "手动";
                        }
                    }
                },
                {
                    field: 'deductType',
                    title: '手续费扣除方式',
                    formatter: function(value, row, index) {
                        if (value==0){
                            return "商户余额扣";
                        }else {
                            return "到账金额扣";
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.withdrawId + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        if (row.withdrawRuleType==1) {
                            actions.push('<a th:if=' + row.withdrawRuleType + ' eq 1 class="btn btn-danger btn-xs"  href="javascript:void(0)" onclick="$.operate.remove(\'' + row.withdrawId + '\')"><i class="fa fa-remove"></i>确定代付</a>');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function showStatistics(){
        $.ajax({
            type: "POST",
            url: prefix + '/showStatistics' ,
            data: $("#formId").serialize() ,
            async: false,
            success: function (data) {
                $("#todayWithdrawAmount").html("今日代付金额: "+data.todayWithdrawAmount);
                $("#todayWithdrawCharge").html("今日代付手续费: "+data.todayWithdrawCharge);
                $("#todayWithdrawSize").html("今日代付笔数: "+data.todayWithdrawSize);
                $("#allWithdrawAmount").html("总代付金额: "+data.allWithdrawAmount);
                $("#allWithdrawCharge").html("总代付手续费: "+data.allWithdrawCharge);
                $("#allWithdrawSize").html("总代付笔数: "+data.allWithdrawSize);
            },
            error: function () {
                $.modal.msgError("未知错误,请联系管理员:统计");
            }
        })
    }
</script>
</body>
</html>